# coding=utf-8
import requests
from Config.config import font_url
from Config.config import client2


def request(key):
    # 查看key是否存在
    try:
        response = client2.find({'_id': key})[0]['response']
        return response
    except:
        try:
            # 构造链接
            url = font_url.format(key[0:2], key)
            response = requests.get(url).text
            # 插入数据库
            try:
                client2.insert({'_id': key, 'response': response})
            except:
                pass
            return response
        except:
            return None


if __name__ == '__main__':
    pass
